<template>
  <el-dialog
    :title="title"
    :visible.sync="dialog.isShow"
    width="800px"
    :close-on-click-modal="false"
  >
    <div>
      <el-form ref="dialogForm" :model="dialogForm" :rules="rules" label-position="top" inline :disabled="pageType==='detail'">
        <el-form-item label="单据类型">
          <el-select v-model="dialogForm.lngreceipttypeid" placeholder="请选择" disabled>
            <el-option
              v-for="item in receipttypeList"
              :key="item.lngreceipttypeid"
              :label="item.strreceipttypename"
              :value="item.lngreceipttypeid"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="控制方式" prop="bytcontroltype">
          <el-select v-model="dialogForm.bytcontroltype" placeholder="请选择">
            <el-option
              v-for="item in bytcontroltypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="编码规则" prop="bytrule">
          <el-select v-model="dialogForm.bytrule" placeholder="请选择">
            <el-option
              v-for="item in bytruleList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-table
          ref="table"
          :data="dialogForm.receiptprefixList"
          :header-cell-style="{background:'#F5F4F7'}"
          stripe
          border
          highlight-current-row
          height="300"
          style="width: 100%;margin-top:20px;"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60"
            align="center"
          />
          <el-table-column
            prop="stroperatorcode"
            label="操作员编码"
          />
          <el-table-column
            prop="stroperatorname"
            label="操作员名称"
          />
          <el-table-column
            prop="strprexreceiptno"
            label="前缀"
          >
            <template v-slot="scope">
              <el-input v-model="scope.row.strprexreceiptno" placeholder="请输入" clearable />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </div>
    <div v-if="pageType!=='detail'" slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="dialog.isShow = false">取 消</el-button>
    </div>
  </el-dialog>

</template>

<script>
import { queryById, editData } from '@/api/system/bill-setting/bill-number-rules'

export default {
  name: 'BillNumberRulesDialog',
  data() {
    return {
      pageType: '',
      dialog: {
        isShow: false,
        editStatus: 0
      },
      receipttypeList: [],
      dialogForm: {},
      rules: {
        bytcontroltype: [
          { required: true, message: '必填项', trigger: 'change' }
        ],
        bytrule: [
          { required: true, message: '必填项', trigger: 'change' }
        ]
      },
      bytcontroltypeList: [
        { label: '年度', value: 0 },
        { label: '年度+期间', value: 1 }
      ],
      bytruleList: [
        { label: '前缀+6位流水号', value: 0 },
        { label: '前缀+年度+6位流水号', value: 1 },
        { label: '前缀+年度+期间+6位流水号', value: 2 }
      ]
    }
  },
  computed: {
    title() {
      return this.pageType === 'edit' ? '编辑' : '查看'
    }
  },
  created() {
  },
  methods: {
    show() {
      this.dialog.isShow = true
    },
    getInfo(id) {
      queryById(id).then(res => {
        if (res.code === 20000) {
          this.dialogForm = res.data
        }
      })
    },
    // 编辑提交
    submitForm() {
      this.$refs['dialogForm'].validate((valid) => {
        if (valid) {
          editData(this.dialogForm, this.dialogForm.lngreceiptruleid).then(res => {
            if (res.code === 20000) {
              this.$message.success(res.message)
              this.dialog.isShow = false
              this.$emit('refresh')
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
